#include <iostream>
#include "stock10.h"
// class definition


Stock::Stock(){}

Stock::Stock(const std::string & comp, long n, double pr){
    company = comp;
    if (n < 0)
    {
        std::cout << "n < 0";
        shares = 0;
    }
    else
        shares = n;
    share_val = pr;
    set_tot();
}

using namespace std;
Stock::~Stock(){
    cout << "~Stock" << company << endl;
}

void Stock::buy(long n, double pr){
    if (n < 0)
    {
        cout << "n < 0" << endl;
    }
    else
    {
        shares += n;
        share_val = pr;
        set_tot();
    }
}

void Stock::sell(long n, double pr){
    if (n < 0)
    {
        cout << "n < 0" << endl;
    }
    else
    {
        shares -= n;
        share_val = pr;
        set_tot();
    }
    
}

void Stock::update(double pr){
    share_val = pr;
    set_tot();
}
void Stock::show() const{
    cout << company << " Company " << shares << " * " << share_val << " = " << total_val << endl;
}

const Stock & Stock::topval(const Stock & s) const{
    if (s.total_val > total_val)
    {
        return s;
    }
    else
    {
        return *this;
    }
}


